package com.rui.study.demo.httpclient;

import com.rui.study.commons.util.JwtUtil;

import java.util.HashMap;
import java.util.Map;

import static com.rui.study.demo.httpclient.HttpClient.*;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2018-11-16 14:26
 **/
public class MyHttpClient {

    private static void createAccount(String account) {
        final String url = "http://localhost:8080/userself/v1/account";
        final String json = "{\"account\": \"" + account + "\", \"verifyCode\":\"888888\", \"password\": \"a123456\"}";
        for (int i=0; i<1; i++) {
            Thread t = new Thread(new Runnable() {
                @Override
                public void run() {
                    putJson(url, json);
                }
            });
            t.start();
        }
    }

    private static void deleteAccount() {
        String identify = "yaowr@mpreader.com";
        String url = "http://localhost:8080/userself/v1/account/" + identify;
        delete(url);
    }

    private static void getUnameNumber() {
        String url = "http://localhost:8080/userself/v1/uname-number";
        get(url);
    }

    private static void delUnameNumber() {
        String url = "http://localhost:8080/userself/v1/uname-number";
        delete(url);
    }

    private static void delLock() {
        String method = "registerAccount";
        String url = "http://localhost:8080/userself/v1/lock/" + method;
        delete(url);
    }

    private static void sendEmail() {
        String url = "http://localhost:8080/userself/v2/test";
        get(url);
    }

    private static void sendMsgHasRouting(String routingKey) {
        String url = "http://localhost:8080/userself/v1/test/send-msg?routingKey=" + routingKey;
        get(url);
    }

    private static void sendMsgNoRouting() {
        String url = "http://localhost:8080/userself/v1/test/send-msg-no-routing";
        get(url);
    }

    private static void sendMstWithRec() {
        String url = "http://localhost:8080/userself/v1/test/send-msg/with-rec";
        get(url);
    }

    private static void testFeign() {
        String url = "http://localhost:8080/userself/v1/test/feign";
        postJson(url, "");
    }

    private static void testEnableFoo() {
        String url = "http://localhost:8080/userself/v1/test/enable-foo";
        get(url);
    }

    private static void queryAccount() {
        String url = "http://localhost:8080/userself/v1/account/15438863689349861";
        get(url);
    }

    private static void v1test() {
        String url = "http://localhost:8080/userself/v1/test/enable-foo";
        Map<String, Object> headers = new HashMap<String, Object>();
        headers.put("access_token", JwtUtil.build("yaowr", "third", "abc", -1, null, null));
//        get(url, headers);
        get(url);
    }

    private static void busRefresh() {
        String url = "http://localhost:8080/actuator/bus-refresh";
        post(url);
    }

    private static void abc() {
        String url = "http://localhost:8080/abc";
        post(url);
    }

    private static void testNioServer() {
        String url = "http://localhost:5678";
        get(url);
    }

    private static void attachDownload() {
        String url = "http://localhost:8888/attach/download?filename=a.png";
        get(url);
    }

    private static void shoppingbagTest1() {
        String url = "http://localhost:8888/shoppingbag/download?filename=a.png";
        get(url);
    }

    public static void main(String[] args) {
//        createAccount("13188888888");
//        deleteAccount();
//        getUnameNumber();
//        delUnameNumber();
//        delLock();
//        sendEmail();
//        sendMsgHasRouting("1");
//        sendMsgNoRouting();
//        sendMstWithRec();
//        testFeign();
//        testEnableFoo();
//        queryAccount();
//        v1test();
//        busRefresh();
//        abc();
//        testNioServer();
//        attachDownload();
        shoppingbagTest1();
    }
}
